//
//  UIImage+YDYExtension.m
//  DYSisterAPP
//
//  Created by 杨德勇 on 2016/8/9.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "UIImage+YDYExtension.h"

@implementation UIImage (YDYExtension)
-(instancetype)ydy_circleImage{
    //开启图形上下文
    UIGraphicsBeginImageContext(self.size);
    
    //获取上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    //添加圆形路径
    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
    CGContextAddEllipseInRect(ctx, rect);
    
    //裁剪
    CGContextClip(ctx);
    
    //绘制图片
    [self drawInRect:rect];
    
    //获取图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    //关闭上下文
    UIGraphicsEndImageContext();
    
    return image;
}

+(UIImage *)ydy_circleImageWithImage:(UIImage *)image{
    return [image ydy_circleImage];
}
@end
